package com.itheima.reflect;

import java.io.BufferedReader;
import java.io.FileReader;

public class Demo1_Reflect {

	public static void main(String[] args) throws Exception {
		
		// 没有反射，只用多态技术
		/*Juicer j = new Juicer();
		j.run(new Apple());
		j.run(new Orange());*/
		
		// 利用反射和配置
		BufferedReader br = new BufferedReader(new FileReader("config.properties"));
		Class<?> clazz = Class.forName(br.readLine());
		Fruit f = (Fruit) clazz.newInstance(); // 父类引用指向子类对象
		Juicer j = new Juicer();
		j.run(f);
		br.close();
	}
}

class Juicer {
	public void run(Fruit f) {
		f.squeeze();
	}
}

interface Fruit {
	public void squeeze();
}

class Apple implements Fruit {
	public void squeeze() {
		System.out.println("榨出一杯苹果汁。。。");
	}
}

class Orange implements Fruit {
	public void squeeze() {
		System.out.println("榨出一杯橙汁。。。");
	}
}